import{r as e}from"./DAXXjFlN13g7BR.js";import{ut as t}from"./B603vO-13smUKN.js";import{Ht as n,vn as r,xn as i}from"./CIxmKYxc4tZcJF.js";import{i as a}from"./BVvRFS7mRz5uC.js";var o=e({getWorkspaceContext:()=>d,hasWorkspaceContext:()=>f,setupWorkspaceContext:()=>u}),s=t(`workspace-context`),c;function l(){s.info(`Creating WorkspaceContext`);let e=i(a?.state?.workspace),t=r([]),o=r(!1);function c(){let e=a?.state?.workspaces||{};t.value=Object.values(e).map(e=>({id:e.id,title:e.title}))}c(),a?.state&&(n(()=>a.state.workspace,t=>{e.value!==t&&(e.value=t,s.info(`Workspace changed`,t?.id))},{immediate:!1}),n(()=>a.state.workspaces,()=>{c()},{immediate:!1,deep:!0}));async function l(t){s.info(`Opening workspace`,t),o.value=!0;try{let n=await a.openWorkspace(t);return n&&(e.value=a.state.workspace,localStorage.setItem(`lastWorkspaceId`,t)),n}catch(e){return s.error(`Failed to open workspace`,t,e),!1}finally{o.value=!1}}async function u(e){s.info(`Creating workspace`,e.title),o.value=!0;try{let t=await a.createWorkspace(e.title);return c(),t.id}catch(t){throw s.error(`Failed to create workspace`,e.title,t),t}finally{o.value=!1}}async function d(e){s.info(`Deleting workspace`,e),o.value=!0;try{await a.deleteWorkspace(e),c()}catch(t){throw s.error(`Failed to delete workspace`,e,t),t}finally{o.value=!1}}async function f(){s.info(`Closing workspace`),await a.closeWorkspace(),e.value=void 0}function p(e){return t.value.find(t=>t.id===e)}function m(e){return t.value.some(t=>t.id===e)}async function h(){s.info(`Disposing WorkspaceContext`),await f()}return{currentWorkspace:e,workspaces:t,isLoading:o,openWorkspace:l,createWorkspace:u,deleteWorkspace:d,closeWorkspace:f,getWorkspaceInfo:p,hasWorkspace:m,dispose:h}}function u(){return c?(s.warn(`WorkspaceContext already initialized, returning existing instance`),c):(c=l(),c)}function d(){if(!c)throw Error(`WorkspaceContext not initialized. Call setupWorkspaceContext() first in your app entry.`);return c}function f(){return c!==void 0}export{f as n,o as r,d as t};